<template>
	<view class="uni-margin-wrap">
		<!-- 商品轮播图 -->
		<swiper class="home-swiper" indicator-dots="true" :autoplay="autoplay" :interval="interval" :circular="circular"
		 :duration="duration">
			<swiper-item class="swiper-item" v-for="(item,key) in goods_info.pics" :key="key">
				<image :src="item.pics_big" class="slide-image"  @click="preview(key)" />
			</swiper-item>
		</swiper> 
		
		<view class="goods-info-box" v-if="goods_info.goods_name">
			<!-- 商品价格 -->
			<view class="gooods_price">￥{{goods_info.goods_price}}</view>
			
			<!-- 商品描述区域 -->
			<view class = "goods_desc">
				<!-- 商品名称 -->
				<view class="gooods_name">{{goods_info.goods_name}}</view>
				<!-- 右侧描述区域 -->
				<view class="desc_right">
					<uni-icons type="star" size="18" color="gray"></uni-icons>
					<text>收藏</text>
				</view>
			</view>
			
			<!-- 免运费 -->
			<view class="yf">快递：免运费</view>
		</view>
		
		<!-- 商品详情数据 -->
		<rich-text :nodes="goods_info.goods_introduce"></rich-text>
		
		<!-- 详情底部 -->
		<view class="goods-carts">
			<uni-goods-nav :options="options" :fill="true" :button-group="buttonGroup" @click="onClick"
				@buttonClick="buttonClick" />
		</view>
	</view>
</template>

<script>
	import { toast } from '../../utils/common';
	
	export default {
		data() {
			return {
				autoplay: true, //是否自动切换
				interval: 3000, //自动切换时长
				duration: 1200, //滑动动画时长
				circular: true, //是否自动采用衔接滑动
				goods_info: [] ,//商品详情对象
				
				options: [{
					icon: 'chat',
					text: '客服'
				}, {
					icon: 'shop',
					text: '店铺',
					info: 2,
					infoBackgroundColor: '#007aff',
					infoColor: "#f5f5f5"
				}, {
					icon: 'cart',
					text: '购物车',
					info: 2
				}],
				buttonGroup: [{
						text: '加入购物车',
						backgroundColor: 'linear-gradient(90deg, #FFCD1E, #FF8A18)',
						color: '#fff'
					},
					{
						text: '立即购买',
						backgroundColor: 'linear-gradient(90deg, #FE6035, #EF1224)',
						color: '#fff'
					}
				],
				customButtonGroup: [{
						text: '加入购物车',
						backgroundColor: 'linear-gradient(90deg, #1E83FF, #0053B8)',
						color: '#fff'
					},
					{
						text: '立即购买',
						backgroundColor: 'linear-gradient(90deg, #60F3FF, #088FEB)',
						color: '#fff'
					}
				],
				customButtonGroup1: [{
					text: '立即购买',
					backgroundColor: 'linear-gradient(90deg, #FE6035, #EF1224)',
					color: '#fff'
				}]
			};
		},
		onLoad(options) {
			//获取商品 ID
			const goods_id = options.goods_id
			// 调用商品详情的方法
			this.getGoodsDetail(goods_id)
			//轮播图
			this.swiperPictures();
		},
		methods: {
			async getGoodsDetail(goods_id) {
				const { data:res } = await uni.$http.get('/api/public/v1/goods/detail',{ goods_id })
				if( res.meta.status !== 200 ) return toast("请求数据失败！")
				// 为商品详情对象赋值
				this.goods_info = res.message
			},
			preview(i){
				uni.previewImage({
					current: i,
					
					urls: this.goods_info.pics.map(x=>x.pics_big)
				})
				
			}
		}
	}
</script>

<style lang="scss">
.uni-margin-wrap{
	width: 100%;
	padding-bottom: 50px; //防止被遮盖
	
	.home-swiper{
		height: 750rpx;
		
		.slide-image{
			height: 100%;
			width: 100%;
		}
	}
	
}



.goods-info-box{
	padding-left: 10px;
	
	.gooods_price{
		padding: 10px 0;
		font-size: 18px;
		color: #e64032;
	}
	
	.goods_desc{
		display: flex;
		justify-content: space-between;
		
		.gooods_name{
			font-size: 14px;
			margin-right: 10px;
		}
		
		.desc_right{
			color: gray;
			display: flex;
			width: 100px;
			flex-direction: column; /* 让子元素垂直排列 */
		    justify-content: space-between; /* 垂直方向两端对齐 */
			align-items: center; //居中
			
			font-size: 12px;
			
			border-left: 1px solid #efefef;
		}
		
	}
	
	.yf{
		color: gray;
		font-size: 10px;
		margin: 10px 0;
	}
}

.goods-carts {
	/* #ifndef APP-NVUE */
	display: flex;
	/* #endif */
	flex-direction: column;
	position: fixed;
	left: 0;
	right: 0;
	/* #ifdef H5 */
	left: var(--window-left);
	right: var(--window-right);
	/* #endif */
	bottom: 0;
}


</style>
